import com.qian.api.ddj.util.SignUtils;
import com.yaowk.api.utils.HttpUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.TreeMap;

public class SH {

//    private String KEY = "2fdc4b62676426a5f95eb58f9967d352";
//    private String USERID = "648418";
    private String KEY = "5c2d6f8e4cf3a602b7b95966be775f98";
    private String USERID = "085024";

    @Test
    public void register() {
        Map<String, String> map = new TreeMap<String, String>();
        String txnTime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        map.put("name", "石国权");
        map.put("phone", "18665486370");
        map.put("mchtName", "西安卡尔玛网络科技有限公司");
        map.put("mchtPhone", "18665486370");
        map.put("manageType", "2");
        map.put("manageId", "02");
        map.put("merMark", "西安卡尔玛网络科技有限公司");
        map.put("merAddr", "陕西省西安市高新区高新路00号天地源·枫林绿洲第63幢1单元1层10108号房");
        map.put("corporationName", "石国权");
        map.put("corporationCertNo", "452226199708183617");
        map.put("acctType", "1");
        map.put("acctName", "石国权");
        map.put("IdNumber", "452226199708183617");
        map.put("acctBankName", "中国工商银行");
        map.put("acctNo", "6212261103004717006");
        map.put("settacct_bankno", "102100099996");
        map.put("userid", USERID);
        /** 参与验签的字段 */
        String sign = SignUtils.params(map);
        sign = DigestUtils.md5Hex(sign + KEY);
        /** 上送的值为 */
        map.put("sign", sign);
        map.put("pay_number", txnTime);
        map.put("orderCode", "kl_Register");
        String baowen = SignUtils.params(map);
        System.out.println("上送的报文为：" + baowen);
        String sr = HttpUtils.post("http://extman.kefupay.cn/newWechats/newWeChatpayment_mobile.action", baowen);
        System.out.println(sr);
    }

    @Test
    public void pay() {
        Map<String, String> map = new TreeMap<String, String>();
        String orderDate = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        map.put("subMchId", "000000295072");
        map.put("orderDate", orderDate);
        map.put("body", "商品");
        map.put("amount", "0.01");
        map.put("productId", "商品名称");
        map.put("notifyUrl", "http://www.baidu.com");
        map.put("userid", USERID);
        /** 参与验签的字段 */
        String sign = SignUtils.params(map);
        sign = DigestUtils.md5Hex(sign + KEY);
        /** 上送的值为 */
        map.put("sign", sign);
        map.put("pay_number", orderDate);
        map.put("orderCode", "kl_WXPay");
        String baowen = SignUtils.params(map);
        System.out.println("上送的报文为：" + baowen);
        String sr = HttpUtils.post("http://extman.kefupay.cn/newWechats/newWeChatpayment_mobile.action", baowen);
        System.out.println(sr);
    }
}
